<?php
/*
 * @ https://EasyToYou.eu - IonCube v11 Decoder Online
 * @ PHP 7.2 & 7.3
 * @ Decoder version: 1.1.6
 * @ Release: 10/08/2022
 */

// Decoded file for php version 71.
namespace app\shop\controller;

class Admin extends \app\BaseController
{
    protected $model;
    protected $config_model;
    public function __construct(\think\App $app)
    {
        parent::__construct($app);
        $this->model = new \app\shop\model\Admin();
    }
    public function login()
    {
        initLogin();
        $input = json_decode($this->request->getInput(), true);
        $dis = ["username" => $input["username"]];
        $data = $this->model->dataInfo($dis);
        if(empty($data)) {
            return $this->error("该用户不存在", 400);
        }
        if($data["passwd"] != checkPass($input["passwd"])) {
            return $this->error("密码错误", 400);
        }
        $result["user"] = $data;
        $result["token"] = uuid();
        if(empty($result["token"])) {
            return $this->error("系统错误", 400);
        }
        setUserForToken($result["token"], $data, 99999999);
        return $this->success($result);
    }
    public function success($data, $code = 200)
    {
        $result["data"] = $data;
        $result["code"] = $code;
        $result["sign"] = NULL;
        if(!empty($this->_token)) {
            $result["sign"] = createSimpleSign($this->_token, is_string($data) ? $data : json_encode($data));
        }
        return $this->response($result, "json", $code);
    }
    public function error($msg, $code = 400)
    {
        $result["error"] = \think\facade\Lang::get($msg);
        $result["code"] = $code;
        return $this->response($result, "json", 200);
    }
    protected function response($data, $type = "json", $code = 200)
    {
        return \think\Response::create($data, $type)->code($code);
    }
}

?>